package com.clei.utils.mqtt;

import java.util.Arrays;

/**
 * mqtt property
 *
 * @author Y
 * @date 2024-01-02
 **/
public class MqttProperty {

    /**
     * clientId
     */
    private String clientId;

    /**
     * url
     */
    private String url;

    /**
     * username
     */
    private String username;

    /**
     * password
     */
    private String password;

    /**
     * topics 多个以英文逗号分隔
     */
    private String topics;

    /**
     * qos 多个以英文逗号分隔
     */
    private String qos;

    public MqttProperty() {
    }

    public MqttProperty(String clientId, String url, String username, String password) {
        this.clientId = clientId;
        this.url = url;
        this.username = username;
        this.password = password;
    }

    public MqttProperty(String clientId, String url, String username, String password, String topics) {
        this(clientId, url, username, password);
        this.topics = topics;
    }

    public MqttProperty(String clientId, String url, String username, String password, String topics, String qos) {
        this(clientId, url, username, password);
        this.topics = topics;
        this.qos = qos;
    }

    public String getClientId() {
        return clientId;
    }

    public String getUrl() {
        return url;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public String getTopics() {
        return topics;
    }

    public String[] getTopicArr() {
        return null == topics ? null : topics.split(",");
    }

    public Integer[] getQosArr() {
        if (null == qos) {
            return null;
        }
        String[] split = qos.split(",");
        int size = split.length;
        return Arrays.stream(split).map(Integer::valueOf).toArray(Integer[]::new);
    }
}
